'''
    实现自动存取款机的存取款模拟
    1.登陆系统
    2.退出系统
    3.查询余额
    4.取钱业务
    5.存钱业务
    6.交互界面
'''

# 基础账号信息
customer_list = [
    {'name':'zhangsan','password':'12345','account':10000},
    {'name':'lisi','password':'23456','account':18000},
    {'name':'wangwu','password':'34567','account':15000}
]

# 1.登陆系统
def login_sys(name,password):
    ret = False         # 判断账户密码是否输入正确
    val = False         # 判断是否检测到账户 True为检测到账户，False为没有
    jud_list = {}
    jud_list['name'] = name
    jud_list['password'] = password
    for jud_dic in customer_list:
        # 判断账号与密码是否与记录的匹配
        if jud_list['name'] == jud_dic['name']:
            if jud_list['password'] == jud_dic['password']:
                print('登陆成功')
                ret = True
                val = True
                break
            elif jud_list['password'] != jud_dic['password']:
                print('密码输入错误')
                val = True
                break
    if val == False:
        print('没有该账户，如需使用请添加新账户')
    return ret

# 2.退出系统
def logout_sys():
    pass

# 3.查询余额
def show_account(name):
    jud_list = {}
    jud_list['name'] = name
    jud_list['account'] = ''
    for jud_dic in customer_list:
        # 判断账号与密码是否与记录的匹配
        if jud_list['name'] == jud_dic['name']:
           jud_list['account'] = jud_dic['account']
           break
    print('您的账户余额为',jud_list['account'])

    return jud_list['account']

# 4.取钱业务
def withdraw_cash(name,money):
    jud_list = {}
    jud_list['name'] = name
    for jud_dic in customer_list:
        # 判断账号与密码是否与记录的匹配
        if jud_list['name'] == jud_dic['name']:
            # 判断是否能够取出输入的钱
            if jud_dic['account'] >= money:
                jud_list['account'] = jud_dic['account'] - money
                break
            if jud_dic['account'] < money:
                print('您不能取出这么多钱')
                break

    print('本次取出{},还剩余{}'.format(money,jud_list['account']))

    return jud_list['account']

# 5.存钱业务
def save_cash(name,money):
    jud_list = {'name': name}
    for jud_dic in customer_list:
        # 判断账号与密码是否与记录的匹配
        if jud_list['name'] == jud_dic['name']:
            jud_list['account'] = jud_dic['account'] + money
            break
    print('本次存入{},还剩余{}'.format(money,jud_list['account']))

    return jud_list['account']


# # 测试登陆系统
# login_sys('zhangsan','123456')
# # 测试查询余额
# show_account('lisi')
# # 测试取钱
# withdraw_cash('lisi',500)

# 6.界面和交互

while True:
    # 输出初始界面
    print('='*12,'自动存取款系统','='*12)
    name = input('请输入你的账号：')
    password = input('请输入你的密码:')
    ret = login_sys(name,password)
    if ret == False:
        continue
    if ret == True:
        print('{:1} {:15} {:15}'.format(' ','1. 查询余额','2. 账号存款'))
        print('{:1} {:15} {:15}'.format(' ','3. 用户取款','4. 退出系统'))
        print('='*40)
        key = input('请输入对应的选择')
        # 根据输入操作值，执行对应操作
        if key == '1':
            print('='*12,'查询余额','='*12)
            show_account(name)
            input('按回车继续：')
        elif key == '2':
            print('=' * 12, '添加存款金额', '=' * 12)
            money = input('请输入存入金额：')
            save_cash(name,money)
            input('按回车继续：')
        elif key == '3':
            print('=' * 12, '请输入取款金额', '=' * 12)
            money = input('请输入存入金额：')
            withdraw_cash(name,money)
            input('按回车继续：')
        elif key == '4':
            logout_sys()
            print('=' * 12, '再见', '=' * 12)
            break
        else:
            print('=' * 12, '操作无效', '=' * 12)
